package com.robot.ad.controller;

import com.robot.ad.pojo.Banner;
import com.robot.ad.service.BannerService;
import entity.Result;
import entity.StatusCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * banner控制器层
 *
 * @author wuyunbin
 */
@RestController
@CrossOrigin
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 首页轮播图列表
     *
     * @return
     */
    @RequestMapping(value = "index", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Result thirdFindBannersByStatus(@RequestBody Banner banner) {
        if (banner.getAreaList() == null || "".equals(banner.getAreaList())) {
            logger.info("getAreaList=" + banner.getAreaList());
            return new Result(StatusCode.SUCCESS_QUERY, bannerService.findAllByStatusAndDeletedAtIsNullOrderBySortDesc("1"));
        }
        return new Result(StatusCode.SUCCESS_QUERY, bannerService.findAllByStatusAndAreaListOrderBySortDesc("1", banner.getAreaList()));
    }
}
